home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1999 November / SOTMC_Nov1999-Ultimate.iso / mac / REALbasic ƒ / Examples / Applications / odummo ƒ / Read Me! < prev   
Encoding:
Text File  |  1998-08-27  |  2.0 KB  |  38 lines  |  [ttro/ttxt]

  1. This is a game of Othello, also known as Reversi. No computer
  2. "intelligence" is involved; the computer chooses its moves at random.
  3. (That's the only way I can ever win, and even so I lose most of the time!)
  4. So it's a "dumb" Othello, which is why I call it Odummo.
  5.  
  6. The challenge here was to implement the rules of the game: the computer
  7. must know whether the user's proposed move is legal, must know what all its
  8. own legal moves are, and when it or the user makes a move, must "flip" the
  9. correct pieces.
  10.  
  11. At first, I expected this to be an arduous programming task. Let's say the
  12. user clicks an empty square. It's legal to move there if there is an
  13. adjacent square with the computer's color piece on it, which leads,
  14. continuing in the same direction, either to a piece of the user's color or
  15. to another piece with the computer's color which leads, continuing in the
  16. same direction... And so on. It sounds like a mess. It sounds as if I'm
  17. going to need some sort of supplementary array of legal moves, which will
  18. have to be examined with loops or recursion or something.
  19.  
  20. But not at all! REALBasic is object-based. So, let every square be an
  21. object. Now the collection of squares (the playing surface itself) *is* my
  22. array. And since they are objects, squares can query one another. Thus, the
  23. square where the user has clicked only has to query the squares adjacent to
  24. it: "Have you got a piece that's the computer's color? You do? Well then,
  25. do you lead to a piece that's the user's color?" Now it's up to the square
  26. being queried to answer this question, by itself querying the *next* square
  27. in the same direction - and so on. What any *one* square has to know how to
  28. do turns out to be extremely simple.
  29.  
  30. The result was that in the end it took me considerably less than a 24-hour
  31. period to write the program - and much of that time was spent in other
  32. activities such as sleeping, eating, reading email, doing a laundry at the
  33. laundromat, and going for a run. To me, that's a real testimony to the
  34. power of the REALBasic object model.
  35.  
  36. Matt Neuburg
  37. matt@tidbits.com
  38. http://www.tidbits.com